<template>
  <!-- 计算公式维护 -->
  <base-breadcrumb :title="$route.meta.title">
    <a-card :bordered="false">
      <!-- 表格 -->
      <list-table
        ref="table"
        :page-keys="['pageNum', 'pageSize']"
        tableLayout="fixed"
        size="default"
        rowKey="id"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        :showPage="false"
      >
        <template
          slot="formula"
          slot-scope="text"
        >
          <span v-html="text"></span>
        </template>
        <template
          slot="action"
          slot-scope="text, record"
        >
          <MoreButton>
            <span v-btnPermission="[{code:'seex_pm_046_edi_01',ident:'prma_seex'},{code:'buco_pm_046_edi_01',ident:'prma_buco'}]">
              <a @click="handleManage(1, record)">编辑</a>
            </span>
          </MoreButton>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import BasePage from '@/views/basePage' // 基础配置
import { api } from '@/api/project/performanceAnalysis'
import MoreButton from '@/components/MoreButton'

const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    customRender() {
      return arguments[2] + 1
    }
  },
  {
    title: '指标名称',
    dataIndex: 'name',
    width: 240
  },

  {
    title: '公式',
    dataIndex: 'formula',
    width: 540,
    scopedSlots: { customRender: 'formula' }
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: 180,
    align: 'center',
    scopedSlots: { customRender: 'action' }
  }
]
export default {
  name: 'a' + Date.now(),
  extends: new BasePage(),
  components: {
    STable,
    MoreButton
  },
  data() {
    this.columns = columns

    return {
      queryParam: {}, // 查询参数

      loadData: async (parameter) => {
        // const requestParameters = Object.assign({}, parameter, { param: this.queryParam })

        return api.listCalculateFormula({}).then((res) => {
          return res
        })
      }
    }
  },
  methods: {
    // 操作栏
    handleManage(type, record) {
      let query = {
        editModel: type
      }
      if (record && record.id) {
        query.id = record.id
        query.code = record.code
      }
      this.$router.push({
        name: 'updateCalculateFormula',
        query
      })
    }
  }
}
</script>
